//
//  WDPBaseItemView.m
//  WDPubLib
//
//  Created by wujianrong on 16/4/19.
//  Copyright © 2016年 wanda. All rights reserved.
//

#import "WDPBaseItemView.h"

@implementation WDPBaseItemView

-initWithHeight:(CGFloat)height
{
    self = [super initWithFrame:CGRectMake(0, 0, 0, height)];

    return self;
}

-initWithWidth:(CGFloat)width
{
    self = [super initWithFrame:CGRectMake(0, 0, width, 0)];
    
    return self;
}

- (BOOL)isVisible
{
    if ([self spacingWithScreen] > 0) {
        return NO;
    } else {
        return YES;
    }
}

/**
 *  底部距离屏幕高度
 *
 *  @return <#return value description#>
 */
- (CGFloat)spacingWithScreen
{
    CGRect itemRect = self.frame;
    CGRect currentRect = [self.superview convertRect:itemRect toView:nil];
    CGFloat bottom = currentRect.origin.y + currentRect.size.height;
    
    CGFloat margin = bottom - SCREEN_HEIGHT;
    
    return margin;
}

- (void)updateWithDataModel:(id)dataModel callBack:(wdpCallBackBlock)callBack
{
    if (callBack != nil) {
        _callback = callBack;
    }
}

- (void)updateMarginWithHeight:(CGFloat)height {
    if (height + self.frame.size.height > SCREEN_HEIGHT-EMStatusBarHeight) {
        self.wdpMarginUp = 10;
    }else {
        CGFloat letfHeight = SCREEN_HEIGHT -EMStatusBarHeight - height - self.frame.size.height;
        CGFloat marginUp = letfHeight - self.wdpMarginDown;
        if (marginUp >=0) {
            self.wdpMarginUp = letfHeight - self.wdpMarginDown;
        } else {
            self.wdpMarginUp = 0;
        }
    }
}

@end
